package tjs.study.notes.dotest.jdk.thread;

import tjs.study.notes.base.common.TestBuiUtils;

import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

/**
 * Created by Nicky.Tang on 2021/11/16 4:16 下午
 *
 * @since 02.12.10
 */
public class DoTestAdd {
    public static final LongAdder la = new LongAdder();
    protected static final AtomicLong al = new AtomicLong();

    public static void main(String[] args) {
        new TestBuiUtils().desc("LongAdder").times(20).threadNum(1000).functionTest((taskNum) -> {
            la.increment();//max:92; min:52; avg:63; sum:1266
        }).doTestThread().printAll();

        new TestBuiUtils().desc("AtomicLong").times(20).threadNum(1000).functionTest((taskNum) -> {
            al.incrementAndGet();//max:89; min:53; avg:65; sum:1317
        }).doTestThread().printAll();
        System.out.println("la: " + la.sum() + " al: " + al.get());
    }
}
